package org.example.modules.AliOSS.sevice.Impl;

import lombok.extern.slf4j.Slf4j;
import org.example.common.utils.OSSUtil;
import org.example.common.utils.ThreadLocalUtil;
import org.example.modules.AliOSS.sevice.FileUploadSevice;
import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.User;
import org.example.modules.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description FileUploadSeviceImpl
 * @Author xiaotian
 * @Date 2025-04-05
 */
@Service
@Slf4j
public class FileUploadSeviceImpl implements FileUploadSevice {

    @Autowired
    private UserService userService;
    @Override
    public String uploadImg(MultipartFile file) {
        try {
            // 调用工具类上传文件到 OSS
            String fileUrl = OSSUtil.uploadFile(file);
            User user= userService.getUserInfoByUserName(ThreadLocalUtil.getUserId());
            user.setAvatarUrl(fileUrl);
            userService.updateIngo(user);
            // 返回成功响应
            return fileUrl;
        } catch (Exception e) {
            e.printStackTrace();
            return "文件上传失败";
        }
    }
    @Override
    public String uploadImg1(MultipartFile file) {
        try {
            // 调用工具类上传文件到 OSS
            String fileUrl = OSSUtil.uploadFile(file);
            // 返回成功响应
            log.info(":{}",fileUrl);
            return fileUrl;
        } catch (Exception e) {
            e.printStackTrace();
            return "文件上传失败";
        }
    }
}
